import {defHttp} from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";

const { createConfirm } = useMessage();

enum Api {
  list = '/yuedupeihe/yuedupeihebumenbiao/list',
  save='/yuedupeihe/yuedupeihebumenbiao/add',
  edit='/yuedupeihe/yuedupeihebumenbiao/edit',
  deleteOne = '/yuedupeihe/yuedupeihebumenbiao/delete',
  deleteBatch = '/yuedupeihe/yuedupeihebumenbiao/deleteBatch',
  importExcel = '/yuedupeihe/yuedupeihebumenbiao/importExcel',
  exportXls = '/yuedupeihe/yuedupeihebumenbiao/exportXls',
  receive = '/yuedupeihe/yuedupeihebumenbiao/jieshou',
  peihezhuguanList = '/yuedupeihe/yuedupeihebumenbiao/peihezhuguan',
  choosePeihezhuguan = '/yuedupeihe/yuedupeihebumenbiao/chosoePeihezhuguan',
  shenhefankuiList = '/yuedushenhe/yuedushenhefankuibiao/list',
  shenhefankui = '/yuedushenhe/yuedushenhefankuibiao/tongguo',
  peihebumenchuliqingkuang = '/yuedushenhe/yuedushenhefankuibiao/chakan',
}
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;
/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
/**
 * 列表接口
 * @param params
 */
export const list = (params) =>
  defHttp.get({url: Api.list, params});
//接收
export const receive = (params) =>
  defHttp.post({url: Api.receive, params});

//配合主管列表
export const peihezhuguanList = () =>
  defHttp.get({url: Api.peihezhuguanList});

//选择配合主管
export const choosePeihezhuguan = (params) =>
  defHttp.post({url: Api.choosePeihezhuguan, params});

//审核反馈列表
export const shenhefankuiList = (params) =>
  defHttp.post({url: Api.shenhefankuiList, params});

//通过
export const shenhefankui = (params) =>
  defHttp.post({url: Api.shenhefankui, params});

//查看
export const peihebumenchuliqingkuang = (params) =>
  defHttp.post({url: Api.peihebumenchuliqingkuang, params});
/**
 * 删除单个
 */
export const deleteOne = (params,handleSuccess) => {
  return defHttp.delete({url: Api.deleteOne, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
/**
 * 批量删除
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}
/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({url: url, params});
}
